Skip to content

Refuse to encrypt to more recipient stanzas than a header holds - #151

Merged
pscheid92 merged 4 commits into
mainfrom
fix/go-age-1.4.0-stanza-limit-on-write
Dec 3, 2026
Merged

pscheid92 merged 4 commits into
mainfrom
fix/go-age-1.4.0-stanza-limit-on-write

Conversation

@pscheid92

Copy link
Copy Markdown
Owner

One of the differences from go-age 1.4.0 found in #150.

The problem

A header holds at most 1,024 recipient stanzas: go-age reads no more, and neither does AgeSharp unless AgeDecryptOptions.MaxRecipientStanzas is raised. AgeSharp still wrote more. Encrypting to 1,025 recipients succeeded, and reading the file back failed with header contains more than 1024 recipient stanzas. go-age refuses to write such a header since v1.4.0 (2fceb23).

The change

Encrypting to more than 1,024 recipient stanzas is an AgeException, checked where every encrypt path builds its header (Recipients.BuildHeader), so before anything reaches the caller's streams.

  • More than 1,024 recipients are refused before any of them is asked to wrap, since each writes at least one stanza. No plugin is started and no hardware key is touched for a file that will not be written. Message: too many recipients: 1025, and a header holds at most 1024 recipient stanzas.
  • Fewer recipients that write too many stanzas between them (a plugin may write several) are refused once they have wrapped. Message: too many recipient stanzas: a header holds at most 1024.
  • Building or parsing a set of any size still works, as go-age parses a recipients file of any length. Only encrypting to it is refused.

The limit when writing is fixed at go-age's value. A reader given a higher limit does not change what AgeSharp writes. No public API changes.

Tests

StanzaLimitOnWriteTests, 13 cases; 11 failed before the change.

  • Exactly 1,024 stanzas, as 1,024 recipients and as one recipient with many stanzas, encrypt and are read back with the default limits.
  • 1,025 recipients are refused by all seven ways of encrypting (Encrypt twice, EncryptAsync, EncryptReader, EncryptWriter, EncryptDetached, EncryptDetachedAsync), at the call, with nothing written to either stream.
  • With 1,025 recipients, none is asked to wrap.
  • 1, 2 and 1,024 recipients that write 1,025 stanzas between them are refused.

Both suites pass locally in the default and the portable build, apart from the age-keygen interop test that #150 fixes (the local go-age is 1.4.0, and this branch does not have that fix).

A header holds at most 1024 recipient stanzas: go-age reads no more, and
neither does AgeSharp by default. AgeSharp still wrote more, a file it
then refused to read. go-age refuses to write one since v1.4.0 (2fceb23).

Encrypting to more is now an AgeException, by every way of encrypting and
before anything is written. More than 1024 recipients are refused before
any of them is asked to wrap, so no plugin is started for a file that
will not be written; fewer recipients that write too many stanzas between
them are refused once they have.
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.72%. Comparing base (bbd303c) to head (3aac363).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #151   +/-   ##
=======================================
  Coverage   97.72%   97.72%           
=======================================
  Files          78       78           
  Lines        5092     5096    +4     
  Branches      697      699    +2     
=======================================
+ Hits         4976     4980    +4     
  Misses         70       70           
  Partials       46       46           
Flag Coverage Δ
macos-latest 97.62% <100.00%> (+<0.01%) ⬆️
ubuntu-latest 97.68% <100.00%> (+<0.01%) ⬆️
windows-latest 97.62% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pscheid92
pscheid92 merged commit 7c8e166 into main Dec 3, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant